<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
    >
      <!-- <el-form-item label="油企id" prop="enterpriseId">
        <el-input
          v-model="queryParams.enterpriseId"
          placeholder="请输入油企id"
          clearable
          size="small"
        />
      </el-form-item> -->
      <!-- <el-form-item label="油站id" prop="activityId">
       <el-select v-model="queryParams.activityId" placeholder="对应的立减活动" >
              <el-option
                v-for="item in reductionActivityList"
                :key="item.activityId"
                :label="item.activityName"
                :value="item.activityId"
                >
              </el-option>
            </el-select>
      </el-form-item>
      <el-form-item label="标签" prop="labelId">
        <el-select v-model="queryParams.labelId" placeholder="对应的标签信息" >
              <el-option
                v-for="item in labelList"
                :key="item.id"
                :label="item.labelName"
                :value="item.id"
                >
              </el-option>
            </el-select>
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="global_el_rowStyle">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          type="primary"
          plain
          >重置</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button plain icon="el-icon-plus" size="mini" @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出</el-button
        >
      </el-col>
      <!-- <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar> -->
    </el-row>

    <el-table
      stripe
      v-loading="loading"
      :data="timingPayWayList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="left" />
      <el-table-column label="定时执行" align="left" prop="timeId" />
      <!-- <el-table-column label="油企id" align="left" prop="enterpriseId" /> -->
      <!-- <el-table-column label="所属立减活动的id" v-show="true" align="left" prop="activityId" /> -->
      <!-- <el-table-column label="立减活动" align="left" prop="activityName" /> -->
      <!-- <el-table-column label="修改标签的id" align="left" prop="labelId" v-show="none" /> -->
      <!-- <el-table-column label="标签" align="left" prop="labelName"  /> -->
      <!-- <el-table-column label="油站id" align="left" prop="stationId" />
      <el-table-column label="微信支付id" align="left" prop="wxPayWayId" />
      <el-table-column label="支付宝支付id" align="left" prop="zfbPayWayId" />
      <el-table-column label="微信充值id" align="left" prop="wxRechargePayWayId" /> -->

      <el-table-column
        show-overflow-tooltip="true"
        label="微信支付"
        align="left"
        prop="wxChinese"
      />
      <el-table-column
        width="100"
        label="支付宝支付"
        align="left"
        prop="zfbChinese"
      />
      <el-table-column label="微信充值" align="left" prop="wxRechargeChinese" />

      <el-table-column
        label="创建时间"
        align="left"
        prop="createDate"
        width="180"
      >
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column
        label="修改时间"
        align="left"
        prop="updateDate"
        width="180"
      >
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="执行类型" align="left" prop="timeType">
        <template slot-scope="scope">
          {{ scope.row.timeType == "1" ? "按周执行" : "" }}
          {{ scope.row.timeType == "2" ? "按照月执行" : "" }}
        </template>
      </el-table-column>
      <el-table-column label="时间段" align="left" prop="days" />
      <el-table-column
        label="开始执行时间"
        align="left"
        prop="beginDate"
        width="180"
      >
      </el-table-column>
      <el-table-column
        label="结束执行时间"
        align="left"
        prop="endDate"
        width="180"
      >
      </el-table-column>
      <el-table-column
        label="操作"
        align="left"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['customer:label:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['customer:label:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改定时修改标签信息，记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <!-- <el-form-item label="定时执行天数" prop="days">
          <el-input v-model="form.days" placeholder="请输入定时执行天数" />
        </el-form-item> -->
        <el-form-item>
          <p>
            定时执行天数
            <el-radio v-model="form.timeType" label="1">按周选择</el-radio>
            <el-radio v-model="form.timeType" label="2">按月选择</el-radio>
          </p>
          <div style="padding: 20px" v-show="form.timeType == 2">
            <el-checkbox-group v-model="form.daylist">
              <el-checkbox-button
                v-for="day in daysOfMonth"
                :label="day"
                :key="day"
                >{{ day }}</el-checkbox-button
              >
            </el-checkbox-group>
          </div>
          <div style="padding: 20px" v-show="form.timeType == 1">
            <el-checkbox-group v-model="form.daylist">
              <el-checkbox-button
                v-for="day in daysOfWeek"
                :label="day"
                :key="day"
                >{{ day }}</el-checkbox-button
              >
            </el-checkbox-group>
          </div>
        </el-form-item>
        <!-- <el-form-item label="油企id" prop="enterpriseId">
          <el-input v-model="form.enterpriseId" placeholder="请输入油企id" />
        </el-form-item> -->
        <!-- <el-form-item label="所属立减活动的id" prop="activityId">
          <el-input v-model="form.activityId" placeholder="请输入所属立减活动的id" />
        </el-form-item> -->
        <el-form-item label="油站信息" prop="stationId">
          <el-select v-model="form.stationId" placeholder="油站信息">
            <el-option
              v-for="item in stationList"
              :key="item.stationId"
              :label="item.stationName"
              :value="item.stationId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="修改标签的id" prop="labelId">
          <el-input v-model="form.labelId" placeholder="请输入修改标签的id" />
        </el-form-item> -->
        <el-form-item label="微信支付" prop="wxPayWayId">
          <el-select v-model="form.wxPayWayId" placeholder="微信支付">
            <el-option
              v-for="item in wxpayList"
              :key="item.payWayId"
              :label="item.payTypeChinese"
              :value="item.payWayId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支付宝支付" prop="zfbPayWayId">
          <el-select v-model="form.zfbPayWayId" placeholder="支付宝支付">
            <el-option
              v-for="item in zfbpayList"
              :key="item.payWayId"
              :label="item.payTypeChinese"
              :value="item.payWayId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="微信充值" prop="wxRechargePayWayId">
          <el-select v-model="form.wxRechargePayWayId" placeholder="微信充值">
            <el-option
              v-for="item in wxrechargeList"
              :key="item.payWayId"
              :label="item.payTypeChinese"
              :value="item.payWayId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item> -->
        <!-- <el-form-item label="创建时间" prop="createDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.createDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改时间" prop="updateDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.updateDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择修改时间">
          </el-date-picker>
        </el-form-item> -->
        <!-- <el-form-item label="执行类型 1按照周执行，2按照月执行" prop="timeType">
          <el-select v-model="form.timeType" placeholder="请选择执行类型 1按照周执行，2按照月执行">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="开始执行时间" prop="beginDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.beginDate"
            type="date"
            value-format="HH-mm-ss"
            placeholder="选择开始执行时间">
          </el-date-picker>
        </el-form-item> -->
        <el-form-item
          label="开始时间"
          prop="beginDate"
          :rules="{
            required: true,
            message: '开始时间',
            trigger: 'change',
          }"
        >
          <el-time-picker
            v-model="form.beginDate"
            placeholder="班次开始时间"
            value-format="HH:mm:ss"
          >
          </el-time-picker>
          {{ form.beginDate }}
        </el-form-item>
        <!-- <el-form-item label="结束执行时间" prop="endDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.endDate"
            type="date"
            value-format="HH-mm-ss"
            placeholder="选择结束执行时间">
          </el-date-picker>
        </el-form-item> -->
        <el-form-item
          label="结束时间"
          prop="endDate"
          :rules="{
            required: true,
            message: '结束时间',
            trigger: 'change',
          }"
        >
          <el-time-picker
            v-model="form.endDate"
            placeholder="结束时间"
            value-format="HH:mm:ss"
          >
          </el-time-picker>
          {{ form.endDate }}
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listLabel,
  getLabel,
  delLabel,
  addLabel,
  updateLabel,
  exportLabel,
  labelRulelist,
} from "@/api/label/label";
import {
  getTimingWay,
  addTimingWay,
  updateTimingWay,
  delTimingWay,
  exportTimingWay,
  listTimingWay,
  getPayWayList,
} from "@/api/dept";
import { listReductionActivity } from "@/api/market/reductionActivity";
import { getEnterpriseList, getStationList } from "@/api/dept";

export default {
  name: "Label",
  data() {
    return {
      daysOfMonth: [
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "10",
        "11",
        "12",
        "13",
        "14",
        "15",
        "16",
        "17",
        "18",
        "19",
        "20",
        "21",
        "22",
        "23",
        "24",
        "25",
        "26",
        "27",
        "28",
        "29",
        "30",
        "31",
      ],
      daysOfWeek: ["1", "2", "3", "4", "5", "6", "7"],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 定时修改标签信息，记录表格数据
      labelList: [],
      timingLabelList: [],
      timingPayWayList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      day: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        daylist: [],
        stationId: null,
        createDate: null,
        updateDate: null,
        beginDate: null,
        endDate: null,
      },
      reductionActivityList: [],
      stationList: [],
      wxpayList: [],
      wxrechargeList: [],
      zfbpayList: [],
      // 表单参数
      form: {
        daylist: [],
      },
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
    this.getStationList();
    this.getWxPayWayList();
    this.getWxRechargePayWayList();
    this.getzfbPayWayList();
  },
  methods: {
    /** 查询定时修改标签信息，记录列表 */
    getList() {
      this.loading = true;
      listTimingWay(this.queryParams).then((response) => {
        this.timingPayWayList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //查询标签的立减活动的集合
    //  getReductionActivityList() {
    //   listReductionActivity({
    //     pageNum: 1,
    //     pageSize: 10000,
    //     activityName: null,
    //     activityUse: "LABEL",
    //     activityType: null,
    //     activityMode: null,
    //   }).then((response) => {
    //     console.log(response);
    //     this.reductionActivityList = response.rows;
    //   });
    // },
    //获取当前油企下的油站信息
    getStationList() {
      getStationList({
        pageSize: 10000,
        pageNum: 1,
        enterpriseId: this.presentEnterprise.enterpriseId,
      })
        .then((res) => {
          this.stationList = res.rows;
        })
        .catch((err) => {});
    },
    //获取当前油企下的微信支付方式信息
    getWxPayWayList() {
      return getPayWayList({
        enterpriseId: this.presentEnterprise.enterpriseId,
        appType: 1,
        useType: 1,
        pageSize: 10000,
        pageNum: 1,
      }).then((res) => {
        console.log("way", res);
        this.wxpayList = res.rows;
      });
    },
    //获取当前油企下的微信充值支付方式信息
    getWxRechargePayWayList() {
      return getPayWayList({
        enterpriseId: this.presentEnterprise.enterpriseId,
        appType: 1,
        useType: 0,
        pageSize: 10000,
        pageNum: 1,
      }).then((res) => {
        console.log("way", res);
        this.wxrechargeList = res.rows;
      });
    },
    //获取当前油企下的支付宝支付方式信息
    getzfbPayWayList() {
      return getPayWayList({
        enterpriseId: this.presentEnterprise.enterpriseId,
        appType: 2,
        useType: 1,
        pageSize: 10000,
        pageNum: 1,
      }).then((res) => {
        console.log("way", res);
        this.zfbpayList = res.rows;
      });
    },
    //拉去全部标签的集合的方法
    //  getLabelList() {
    //   labelRulelist({
    //     pageNum: 1,
    //     pageSize: 10000,
    //   }).then((response) => {
    //     console.log(response);
    //     this.labelList = response.rows;
    //   });
    // },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        timeId: null,
        daylist: [],
        enterpriseId: null,
        stationId: null,
        wxPayWayId: null,
        zfbPayWayId: null,
        activityId: null,
        wxRechargePayWayId: null,
        delFlag: null,
        timeType: null,
        createDate: null,
        updateDate: null,
        beginDate: null,
        endDate: null,
      };
      console.log(this.form.timeType);
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.timeId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加定时修改支付方式信息，记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const timeId = row.timeId || this.ids;
      getTimingWay(timeId).then((response) => {
        this.form = response.data;
        this.form.daylist = response.data.days.split(",");
        this.open = true;
        this.title = "修改定时支付方式信息，记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.timeId != null) {
            updateTimingWay(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTimingWay(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const timeIds = row.timeId || this.ids;
      this.$confirm(
        '是否确认删除定时修改标签信息，记录编号为"' + timeIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delTimingWay(timeIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有定时修改标签信息，记录数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportTimingWay(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>
